<html>
<head><meta charset="utf-8"><title>How to get name + type of arguments in MIR · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html">How to get name + type of arguments in MIR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217164909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217164909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217164909">(Nov 18 2020 at 17:02)</a>:</h4>
<p>I would like to access to the name and type of every arguments in <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html">MIR</a>.<br>
As far as I understand, the return value always has the index <code>0</code>, then the arguments have the index from <code>1</code> to <code>mir.arg_count</code>. I can access to type with <code>mir.local_decls[index].ty</code> with <code>index</code> being either <code>0</code> (the return type or the index of a given argument + 1.<br>
However, I'm not sure how I should access to a user-readable string for the name of each arguments. I'm not sure if it should be a <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html"><code>Symbol</code></a> or a <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Constant.html"><code>Constant</code></a>. And I'm don't understand how I should get it. Note that I'm expecting that this name is optional since the return value isn't named, and for <code>fn foo(_: i32)</code> I don't know if the name of the first argument is <code>_</code> or <code>None</code>.</p>



<a name="217166782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217166782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217166782">(Nov 18 2020 at 17:15)</a>:</h4>
<p>The <code>var_debug_info</code> field contains the information you want. It is an array of <code>VarDebugInfo</code> values. Each defines the name of a variable and the <code>Place</code> it is in. This <code>Place</code> could be a direct local, or a projection of a local. The later case doesn't happen currently I think, but it can happen in the future when an SROA pass is introduced. There are locals without corresponding <code>VarDebugInfo</code>. These are compiler introduced temporaries or <code>_</code>.</p>



<a name="217166912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217166912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217166912">(Nov 18 2020 at 17:16)</a>:</h4>
<p>What is a SROA?</p>



<a name="217167007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167007">(Nov 18 2020 at 17:17)</a>:</h4>
<p>looks like 'scalar replacement of aggregates' <a href="https://blog.regehr.org/archives/1603">https://blog.regehr.org/archives/1603</a></p>



<a name="217167028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167028">(Nov 18 2020 at 17:17)</a>:</h4>
<p>I'm guessing something like <a href="https://llvm.org/doxygen/classllvm_1_1SROA.html">https://llvm.org/doxygen/classllvm_1_1SROA.html</a></p>



<a name="217167041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167041">(Nov 18 2020 at 17:17)</a>:</h4>
<p>And what is the index to <code>mir.var_debug_info</code>? It doesn't seems to be a <code>Local</code> (so the index of the argument + 1 in the case of the arguments).</p>



<a name="217167100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167100">(Nov 18 2020 at 17:17)</a>:</h4>
<p>It's just a list of debuginfo data</p>



<a name="217167189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167189">(Nov 18 2020 at 17:18)</a>:</h4>
<p>You need to find the parts you're interested in by looking for places that match the locals you want to know the names of</p>



<a name="217167492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167492">(Nov 18 2020 at 17:20)</a>:</h4>
<p>FYI, arguments don't have to be named so you should probably structure your code to handle that. As a contrived example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">x</span><span class="p">((</span><span class="n">z</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span>: <span class="p">(</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="kt">u8</span><span class="p">))</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The argument itself isn't named since it's immediately destructured.</p>



<a name="217167619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217167619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217167619">(Nov 18 2020 at 17:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR/near/217167007">said</a>:</p>
<blockquote>
<p>looks like 'scalar replacement of aggregates' <a href="https://blog.regehr.org/archives/1603">https://blog.regehr.org/archives/1603</a></p>
</blockquote>
<p>Confirmed: <a href="https://queue.acm.org/detail.cfm?id=3212479">https://queue.acm.org/detail.cfm?id=3212479</a></p>



<a name="217168227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217168227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217168227">(Nov 18 2020 at 17:25)</a>:</h4>
<p>Then I guess I need to be able to capture <code>"(z, y)"</code>, from a <code>Span</code>? (I'm not familiar with <code>Span</code>). This still doesn't explains how I can index <code>mir.var_debug_info</code>. It's a <code>Vec</code> and not a <code>VecIndex&lt;Local, _&gt;</code>, so I don't think I can just use the index of a local to index it.</p>



<a name="217168435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217168435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217168435">(Nov 18 2020 at 17:26)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> what are you trying to do?</p>



<a name="217168691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217168691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217168691">(Nov 18 2020 at 17:28)</a>:</h4>
<p>the way rustdoc gets names is here: <a href="https://github.com/rust-lang/rust/blob/c9a48d1d73f71fbe5f2ea72485fd2a8a94e65934/src/librustdoc/html/format.rs#L921">https://github.com/rust-lang/rust/blob/c9a48d1d73f71fbe5f2ea72485fd2a8a94e65934/src/librustdoc/html/format.rs#L921</a><br>
I'd have to look deeper in <code>clean</code> to see where in rustc that comes from</p>



<a name="217168780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217168780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217168780">(Nov 18 2020 at 17:29)</a>:</h4>
<blockquote>
<p>This still doesn't explains how I can index mir.var_debug_info. </p>
</blockquote>
<p>You can't. You have to iterate over the vec and record whatever data you're interested in along the way.</p>



<a name="217169067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217169067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217169067">(Nov 18 2020 at 17:31)</a>:</h4>
<blockquote>
<p>what are you trying to do?</p>
</blockquote>
<p>Accessing a name that the user can understand. I'm trying to extract the dependency relations between the arguments of a function, the arguments to callee function, the return value of callee function and the return value of the function. Then I need to be able to display this graph of dependency.</p>



<a name="217169247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217169247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217169247">(Nov 18 2020 at 17:32)</a>:</h4>
<p>I'm not sure how <code>Span</code>s are coming into play. <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.VarDebugInfo.html"><code>VarDebugInfo.name</code></a> is what you're interested in. You just need to find if there is one for the <code>Local</code> you're interested in.</p>



<a name="217170069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217170069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217170069">(Nov 18 2020 at 17:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR/near/217168227">said</a>:</p>
<blockquote>
<p>Then I guess I need to be able to capture <code>"(z, y)"</code>, from a <code>Span</code>? (I'm not familiar with <code>Span</code>).</p>
</blockquote>
<p>A <code>Span</code> represents a region of code (in terms of raw byte positions in a source file). I think unless you want to point to point some part of the source code to the user, you don't need <code>Span</code>.</p>



<a name="217170201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217170201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217170201">(Nov 18 2020 at 17:40)</a>:</h4>
<blockquote>
<p>You have to iterate over the vec and record whatever data you're interested in along the way.</p>
</blockquote>
<p>I have the <code>mir::Local</code> of the records I want (it's <code>Local(1)</code> to <code>Local(mir.arg_count + 1)</code>), but I don't understand how to filter <code>var_debug_info</code>.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">debug_info</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">&amp;</span><span class="n">mir</span><span class="p">.</span><span class="n">var_debug_info</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">arg</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">mir</span><span class="p">.</span><span class="n">args_iter</span><span class="p">()</span><span class="w"></span>
<span class="w">        </span><span class="k">if</span><span class="w"> </span><span class="o">???</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">printf</span><span class="o">!</span><span class="p">(</span><span class="s">"argument {} is named {}"</span><span class="p">,</span><span class="w"> </span><span class="n">arg</span><span class="p">,</span><span class="w"> </span><span class="n">debug_info</span><span class="p">.</span><span class="n">name</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217170404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217170404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217170404">(Nov 18 2020 at 17:41)</a>:</h4>
<p>Maybe <code>debug_info.place.local</code>?</p>



<a name="217170424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217170424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217170424">(Nov 18 2020 at 17:41)</a>:</h4>
<p>yes, thanks.</p>



<a name="217170505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217170505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217170505">(Nov 18 2020 at 17:42)</a>:</h4>
<p>I hope ;)</p>



<a name="217171878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217171878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217171878">(Nov 18 2020 at 17:51)</a>:</h4>
<p>Yeah, that's basically it. You can improve that a bit by doing the loop only once with something like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">arg_names</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">IndexVec</span>::<span class="n">from_elem_n</span><span class="p">(</span><span class="nb">None</span><span class="p">,</span><span class="w"> </span><span class="n">mir</span><span class="p">.</span><span class="n">arg_count</span><span class="p">);</span><span class="w"></span>

<span class="k">for</span><span class="w"> </span><span class="n">debug_info</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">&amp;</span><span class="n">mir</span><span class="p">.</span><span class="n">var_debug_info</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="c1">// only look at top-level bindings which should be the argument names</span>
<span class="w">  </span><span class="k">if</span><span class="w"> </span><span class="n">debug_info</span><span class="p">.</span><span class="n">source_info</span><span class="p">.</span><span class="n">scope</span><span class="p">.</span><span class="n">index</span><span class="p">()</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">continue</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>

<span class="w">  </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">local</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">debug_info</span><span class="p">.</span><span class="n">place</span><span class="p">.</span><span class="n">as_local</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">arg_names</span><span class="p">[</span><span class="o">*</span><span class="n">local</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">debug_info</span><span class="p">.</span><span class="n">name</span><span class="p">);</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>which gives you an <code>IndexVec&lt;Local, Option&lt;&amp;Symbol&gt;&gt;</code> mapping arguments to names if they were found. </p>
<p>Caveat emptor: I wrote this code in Zulip chat and haven't tested it.</p>



<a name="217203770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20get%20name%20%2B%20type%20of%20arguments%20in%20MIR/near/217203770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR.html#217203770">(Nov 18 2020 at 22:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20to.20get.20name.20.2B.20type.20of.20arguments.20in.20MIR/near/217167007">said</a>:</p>
<blockquote>
<p>looks like 'scalar replacement of aggregates' <a href="https://blog.regehr.org/archives/1603">https://blog.regehr.org/archives/1603</a></p>
</blockquote>
<p>Thanks, it was a very interesting read!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>